/**
 * // Definition for a Node.
 * function Node(val,children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node|null} root
 * @return {number}
 */
function maxDepth(root) {
  let num = 0;
  let numValue = 0;
  let preNumValue = 0;
  let index = 0;
  while (root.length - 1 > index) {
    if (root[index] === null) {
      preNumValue--
    } else {
      numValue++
      if (preNumValue === 0) {
        num++
        preNumValue = numValue
        numValue = 0
      }
    }
    index++
  }
  return num
};

console.log(maxDepth([1, null, 3, 2, 4, null, 5, 6]));